/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.locanet.view;

/**
 *
 * @author guerrero
 */
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

public class SessionListener implements HttpSessionListener {

    public SessionListener() {
    }

    public void sessionCreated(HttpSessionEvent event) {
    }

    public void sessionDestroyed(HttpSessionEvent event) {
        // get the destroying session…
        HttpSession session = event.getSession();
        /*
         * nobody can reach user data after this point because session is invalidated already.
         * So, get the user data from session and save its logout information
         * before losing it.
         * User’s redirection to the timeout page will be handled by the SessionTimeoutFilter.
         */
        // Only if needed
        try {
            prepareLogoutInfoAndLogoutActiveUser(session);
        } catch (Exception e) {
            System.out.println("Error while logging out at session destroyed: " + e.getMessage());
        }
    }

    /**

     * Clean your logout operations.
     */
    public void prepareLogoutInfoAndLogoutActiveUser(HttpSession httpSession) {
        // Only if needed
    }
}
